package app

import (
	"net/http"

	"github.com/gin-gonic/gin"
	"go-papers/pkg/lognew"
)

func CommonResp(c *gin.Context, code int, message string, data interface{}) {
	res := gin.H{
		"code":    code,
		"message": message,
		"data":    data,
	}
	if code != 0 {
		lognew.Error(c, "非200返回", lognew.Fields{"code": code, "msg": message})
	}
	c.JSON(http.StatusOK, res)
}

func ApiResp(c *gin.Context, code int, message string, data interface{}) {
	res := gin.H{
		"code":    code,
		"message": message,
		"data":    data,
	}

	if code != 0 {
		lognew.Error(c, "非200返回", lognew.Fields{"code": code, "msg": message})
	}
	c.JSON(http.StatusOK, res)
}
